package com.microservices.yucloud.appweb.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author zy
 * @date 2019-08-28 17:51
 **/
@AllArgsConstructor
@NoArgsConstructor
@Getter
public enum BizOrderEventsEnum {
    // 创建
    CREATE("create"),
    // 计算
    COMPUTE("compute"),
    // 审核
    REVIEW("review"),
    // 生成
    GENERATE("generate"),
    // 发包
    SEND_PACKAGE("send_package"),
    //完成
    COMPLETE("complete");

    String event;

    /**
     * 判断
     * @param eventName
     * @return
     */
    public static BizOrderEventsEnum getEvent(String eventName) {
        if (StringUtils.isBlank(eventName)) {
            return null;
        }

        Optional<BizOrderEventsEnum> resultOptional = Arrays.asList(BizOrderEventsEnum.values()).parallelStream().filter(eventEnum ->
                StringUtils.equals(eventName, eventEnum.getEvent())).findAny();

        return resultOptional.orElse(null);
    }
}
